home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
seritest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
4KB
|
170 lines
/* serial test program v1.0 */
#define SERPORTEVENTS
#include "exec/types.h"
#include "exec/nodes.h"
#include "exec/lists.h"
#include "exec/ports.h"
#include "exec/libraries.h"
#include "exec/devices.h"
#include "exec/io.h"
#include "devices/serial.h"
struct IOExtSer IORser;
struct MsgPort *port;
char buffer[20];
extern struct MsgPort *CreatePort();
main()
{
int error;
int actual;
unsigned char iof;
unsigned long cc;
unsigned long rbl;
unsigned long brk;
unsigned long baud;
unsigned char rwl;
unsigned char wwl;
unsigned char sf;
unsigned long t0;
unsigned long t1;
open:
/* OPEN the serial.device */
if ((error = OpenDevice (SERIALNAME, 0, &IORser, 0)) != 0) {
printf ("bad news %ld on Open \n", error);
exit (error);
}
/* SET UP the message port in the I/O request */
port = CreatePort (SERIALNAME,0);
IORser.IOSer.io_Message.mn_ReplyPort = port;
/* SET PARAMS for the serial.device */
iof = 0x00;
cc = 0x00;
rbl = 4096;
rwl = 0x08;
wwl = 0x08;
brk = 250000;
baud= 9600;
sf = 0x00;
t0 = 0x51040303;
t1 = 0x03030303;
if ((error = setparams (iof,cc,rbl,rwl,wwl,brk,baud,sf,t0,t1)) != 0) {
printf ("bad news %ld on setup \n", error);
exit (error); /* redundant err msg, but who's counting ?? */
}
writeSer ("\n\015opened ok\n\015", -1);
writeSer ("test of -1 length\n\015", -1);
sendWaitWrite ("this is a sendio test\n\015", 23);
sendWaitWrite ("this is another sendio test\n\015", -1);
writeSer ("\n\015type 16 characters to send to amiga\n\015", -1);
actual = readSer (buffer,16);
writeSer ("\n\015Buffer was :\n\015", 16);
writeSer (buffer, actual);
writeSer ("\n\015end\n\015", -1);
writeSer ("54321", 5);
/* CLOSE the serial.device */
CloseDevice (&IORser);
DeletePort (port);
exit (0);
}
/* SERIAL I/O functions */
setparams(is,ctl_char,rbuf_len,rlen,wlen,brk,baud,sf,ta0,ta1)
unsigned char is;
unsigned long ctl_char;
unsigned long rbuf_len;
unsigned char rlen;
unsigned char wlen;
unsigned long brk;
unsigned long baud;
unsigned char sf;
unsigned long ta0;
unsigned long ta1;
{
int error;
IORser.IOSer.io_Flags = is;
IORser.io_CtlChar = ctl_char;
IORser.io_ReadLen = rlen;
IORser.io_BrkTime = brk;
IORser.io_Baud = baud;
IORser.io_WriteLen = wlen;
IORser.io_StopBits = 0x01;
IORser.io_RBufLen = rbuf_len;
IORser.io_SerFlags = sf;
IORser.IOSer.io_Command = SDCMD_SETPARAMS;
IORser.io_TermArray.TermArray0 = ta0;
IORser.io_TermArray.TermArray1 = ta1;
if ((error = DoIO (&IORser)) != 0) {
printf ("serial.device setparams error %ld \n", error);
exit (1);
}
return (error);
}
readSer(data,length)
char *data;
ULONG length;
{
int error;
IORser.IOSer.io_Data = data;
IORser.IOSer.io_Length = length;
IORser.IOSer.io_Command = CMD_READ;
if ((error = DoIO (&IORser)) != 0) {
printf ("serial.device read error %ld \n", error);
exit (1);
}
return (IORser.IOSer.io_Actual);
}
writeSer(data,length)
char *data;
int length;
{
int error;
IORser.IOSer.io_Data = data;
IORser.IOSer.io_Length = length;
IORser.IOSer.io_Command = CMD_WRITE;
if ((error = DoIO (&IORser)) != 0) {
printf ("serial.device write error %ld \n", error);
exit (1);
}
return (error);
}
sendWaitWrite(data,length)
char *data;
int length;
{
int error;
IORser.IOSer.io_Data = data;
IORser.IOSer.io_Length = length;
IORser.IOSer.io_Command = CMD_WRITE;
SendIO (&IORser);
if ((error = WaitIO (&IORser)) != 0) {
printf ("serial.device waitio error %ld \n", error);
exit (1);
}
return (IORser.IOSer.io_Actual);
}